package org.soarsky.wealthchengdu.google.map;

import android.graphics.Point;

public class PointContorl {
	private int width=0, heigth=0;
	private final int ALLOW_DRAW_OFFSET = 5;
	public PointContorl(){
	}
	public void  screenSizeChange(int width, int heigth){
		this.width = width;
		this.heigth = heigth;
	}
	public boolean isInTheScreen(Point point){
		return  (point!=null&&point.x >= 0 && point.x <= width && point.y >= 0
				&& point.y <= heigth);
	}
	public boolean isInTheScreen(Point point,int width, int heigth){
		return  (point!=null&&point.x >= 0 && point.x <= width && point.y >= 0
				&& point.y <= heigth);
	}
	public boolean isOverlap(Point pointPrev,Point pointNext){
		return (null!=pointPrev&&null!=pointNext&&Math.abs(pointPrev.x - pointNext.x) > ALLOW_DRAW_OFFSET
				&& Math.abs(pointPrev.y - pointNext.y) > ALLOW_DRAW_OFFSET);
		
	}
	private float currentBraring = 0f;
	private float offsetBraring = 0f;
	public  float getBraring(int orientation,float sersorBraring,float gpsBraring,boolean gpsFixed,boolean horizontal) {
		if(sersorBraring<0)return -1;
		gpsBraring = getBraring(orientation,gpsBraring,true,horizontal);
		if(gpsFixed&&currentBraring!=gpsBraring){
			currentBraring=gpsBraring;
			offsetBraring= sersorBraring -gpsBraring; 
		}
		sersorBraring = sersorBraring - offsetBraring;
		return getBraring( orientation, sersorBraring, false,horizontal);
	}
	private float getBraring(int orientation,float braring,boolean type,boolean horizontal){
		
		switch (orientation) {
		case 0:
		break;
		case 1:
			if(horizontal){
			if(type){
				braring = braring+270;
				braring  =braring>360?braring-360:braring;
			}else {
				braring = braring-270;
				braring  =braring>0?braring:360+braring;
			}
			}
			
		break;
		case 2:
			if(!horizontal){
			if(type){
				braring = braring+180;
				braring  =braring>360?braring-360:braring;
			}else{
				braring = braring-180;
				braring  =braring>0?braring:360+braring;
			}
			}
		break;
		case 3:
			if(horizontal){
				if(type){
					braring = braring+90;
					braring  =braring>360?braring-360:braring;
				}else {
					braring = braring-90;
					braring  =braring>0?braring:360+braring;
				}
			}
		break;
		default:
		break;
	}
		return braring;
	}
}
